package com.ss.android.image;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.ss.android.common.load.MultiAsyncLoader.LoaderProxy;
import com.ss.android.image.model.ImageInfo;

import java.util.Collection;
import java.util.Iterator;

final class AvatarLoaderProxy implements LoaderProxy<String, ImageInfo, Void, ImageView, Bitmap> {
    private final AvatarLoader mAvatarLoader;

    AvatarLoaderProxy(AvatarLoader avatarLoader) {
        this.mAvatarLoader = avatarLoader;

    }

    public final Bitmap doInBackground(String key, ImageInfo param, Void extra) {
        return this.mAvatarLoader.loadAvatar(key, param);
    }

    public final void onLoaded(String key, ImageInfo param, Collection<ImageView> imageViews, Bitmap result) {
        if (this.mAvatarLoader.c) {
            if (this.mAvatarLoader.d != null) {
                this.mAvatarLoader.d.a(result);
            }

            if (key == null) {
                return;
            }

            if (imageViews == null) {
                return;
            }

            if (result == null) {
                return;
            }

            if (result != null) {
                this.mAvatarLoader.mLRUWeakCache.put(key, result);
            }

            Iterator<ImageView> iterator = imageViews.iterator();
            while (iterator.hasNext()) {
                ImageView imageView = iterator.next();
                if (!key.equals(imageView.getTag())) {
                    continue;
                }
                imageView.setImageBitmap(result);
                if (result != null) {
                    imageView.setBackgroundDrawable(null);
                }
                imageView.setTag(null);
            }
        }
    }
}

